﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace Telmex
{
    /// <summary>
    /// Extension methods for <see cref="System.Net.HttpWebResponse"/>.
    /// </summary>
    public static class HttpWebResponseExtensions
    {
        /// <summary>
        /// Read the response stream as a string. Note that the stream will be closed and can no longer be used.
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        public static string ReadString(this HttpWebResponse response)
        {
            string rawData;

            using (var stream = response.GetResponseStream())
            {
                using (var reader = new StreamReader(stream, System.Text.Encoding.GetEncoding("utf-8")))
                {
                    rawData = reader.ReadToEnd();
                }
            }

            return rawData;
        }
    }
}
